package cn.wolfcode.education.util;

import java.util.Calendar;
import java.util.Date;

public class DateUtil {
    //获取当天最后一秒钟
    public static Date getEndDate(Date date){
        Calendar c = Calendar.getInstance();
        //把endDate的时间赋给日历类
        c.setTime(date);
        //设置为23:59:59
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        //日历类转换为日期类
        return c.getTime();
    }

    /**
     * 获取当天的第一秒
     * @param date
     * @return
     */
    public static Date getBeginDate(Date date){
        Calendar c = Calendar.getInstance();
        //把endDate的时间赋给日历类
        c.setTime(date);
        //设置为23:59:59
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        //日历类转换为日期类
        return c.getTime();
    }
}
